# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import time

class CsdnSpiderPipeline(object):
    pipeline_count = 1

    def process_item(self, item, spider):
        #delete speical char ¥
        price = item["coursePrice"][0].strip()
        if(price != "免费"):
            price = price[1:len(price)]

        #combine write string
        fileData = "课程名:" + item["courseName"][0] + "\r"
        fileData += "学员数:" + item["stdNum"][0] + "\r"
        fileData += "课程价格:" + price + "\r"
        fileData += "课时:" + item["courseTimes"][0].strip()

        #write file
        fileName = "D://Work//Python//tmp//" + item["courseId"][0] + ".txt"
        fh = open(fileName, "w")
        fh.write(fileData)
        fh.close()

        return item
